//
//  ZiXunViewController.m
//  MyYiJianKangApp
//
//  Created by 张国文 on 16/5/9.
//  Copyright © 2016年 hangzhouyijiyin. All rights reserved.
//

#import "ZiXunViewController.h"
#import "AFNetworking.h"
#import "ZiXunGeRenPingLunModel.h"
#import "ZiXunModel.h"
#import "PingLunOnZiXunTableViewCell.h"
#import "ZiXunTableViewCell.h"
#import "ZiXunWebViewTableViewCell.h"
#import "SendPingLunViewController.h"
#import "PingListViewController.h"
#import "ProductViewController.h"
#import "UMSocial.h"
#import "HotAndGreatViewController.h"

#define kCurrentUserToken [[NSUserDefaults standardUserDefaults]objectForKey:@"token"]


@interface ZiXunViewController ()<UIWebViewDelegate, UITableViewDataSource, UITableViewDelegate,UMSocialUIDelegate>

@property (nonatomic, strong) UIWebView *myWebView; // 网页

@property (nonatomic, strong) NSMutableDictionary *ziXunContentDic; // 存储咨询的内容

@property (nonatomic, strong) NSMutableArray *hotPingLunArray; // 热门评论

@property (nonatomic, strong) NSMutableArray *pingLunOfZiXunArray; // 咨询的评论数组

@property (nonatomic, strong) NSMutableArray *relateZiXunArray; // 相关咨询

@property (nonatomic, strong) UIScrollView *backGroundView; // 背景

@property (nonatomic, strong) UIImageView *dianZanRenShuImageV; // 点赞人数的图片

@property (nonatomic, strong) UITableView *ziXunTableView;

@property (nonatomic, strong) UILabel *dianZanRenShuLabel; // 点赞人数

@property (nonatomic, strong) UIImageView *shoucangImageV; // 是否收藏图片

@property (nonatomic, strong) UIView *footerView; // 表尾

@property (nonatomic, strong) NSTimer *myTimer; // 检查请求是否超时
@property (nonatomic, assign) NSInteger numberOfTime; // 存储请求时间

@property (nonatomic, assign) __block BOOL canShouCang; // 是否可以收藏，默认为可以

@property (nonatomic, assign) __block BOOL canZhengTiDianZan; // 是否可以对咨询点赞，默认为可以

@property (nonatomic, assign) __block BOOL pingLunShiFouKeYiDianZan; // 是否可以对评论点赞，默认为可以

@property (nonatomic, assign) __block BOOL canClickLaJiTong; // 是否可以点击垃圾桶,默认为可以


@end

@implementation ZiXunViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    self.tabBarController.tabBar.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:YES];
    // 关闭动画
    [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] stopAnimation];
    // 关闭计时器
    [self.myTimer invalidate];
    self.numberOfTime = 0;
}




- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    // navi的修改
    [self changeNavigation];
    
    // 检查网络并建立数据源
    [self searchNetAndAddData];
    
    // 是否可以收藏、是否可以对咨询点赞、是否可以对评论进行点赞、是否可以点击垃圾桶
    self.canShouCang = YES;
    self.canZhengTiDianZan = YES;
    self.pingLunShiFouKeYiDianZan = YES;
    self.canClickLaJiTong = YES;
//    NSLog(@"当前用户的token = %@", kCurrentUserToken);
}



// navi的修改
- (void)changeNavigation
{
    [self.navigationController.navigationBar setTranslucent:NO];
    self.navigationItem.title = @"详情";
    // 左边
    UIImageView *leftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    leftImageView.image = [UIImage imageNamed:@"houtui"];
    UITapGestureRecognizer *leftTapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(lastPage:)];
    [leftImageView addGestureRecognizer:leftTapGes];
    UIBarButtonItem *leftFirstItem = [[UIBarButtonItem alloc] initWithCustomView:leftImageView];
    self.navigationItem.leftBarButtonItem = leftFirstItem;
}

#pragma - 收藏和分享
- (void)collectAndShare
{
    //右边
    UIImageView *fenxiangImageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    fenxiangImageV.image = [UIImage imageNamed:@"fenxiang"];
    UITapGestureRecognizer *fenxiangTapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(fenxiang:)];
    [fenxiangImageV addGestureRecognizer:fenxiangTapGes];
    UIBarButtonItem *rightFirstItem = [[UIBarButtonItem alloc] initWithCustomView:fenxiangImageV];
    
    self.shoucangImageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    NSString *isCollect = [NSString stringWithFormat:@"%@", [self.ziXunContentDic valueForKey:@"is_collected"]];
    if ([isCollect isEqualToString:@"0"]) {
        // 说明未收藏
        self.shoucangImageV.image = [UIImage imageNamed:@"weishoucang-chanpin"];
    } else if ([isCollect isEqualToString:@"1"]) {
        // 说明收藏过了
        self.shoucangImageV.image = [UIImage imageNamed:@"suocangguo-chanpin"];
    }
    
    UITapGestureRecognizer *shoucangTapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(shoucang:)];
    [self.shoucangImageV addGestureRecognizer:shoucangTapGes];
    UIBarButtonItem *rightSecondItem = [[UIBarButtonItem alloc] initWithCustomView:_shoucangImageV];
    self.navigationItem.rightBarButtonItems = @[rightFirstItem, rightSecondItem];
}

#pragma mark - 返回
- (void)lastPage:(UITapGestureRecognizer *)tapGes
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 分享
- (void)fenxiang:(UITapGestureRecognizer *)tapGes
{
    NSLog(@"分享");
    if (self.ziXunContentDic) {
        NSString *content=[self.ziXunContentDic valueForKey:@"content_url"];
        [self shareWithContent:content];
    }else{
        [self.view showTiShiMessage:@"程序员GG开了个小差"];
    }
}

#pragma mark 分享
-(void)shareWithContent:(NSString *)content
{
    [UMSocialSnsService presentSnsIconSheetView:self
                                         appKey:@"507fcab25270157b37000010"
                                      shareText:[NSString stringWithFormat:@"%@",content]
                                     shareImage:nil
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToWechatSession,UMShareToWechatTimeline,UMShareToSina,UMShareToTencent,UMShareToQzone,UMShareToQQ,UMShareToRenren,UMShareToDouban,nil]
                                       delegate:self];
    
}

-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response
{
    //根据`responseCode`得到发送结果,如果分享成功
    if(response.responseCode == UMSResponseCodeSuccess)
    {
        //得到分享到的微博平台名
        NSLog(@"share to sns name is %@",[[response.data allKeys] objectAtIndex:0]);
        [self.view showTiShiMessage:@"分享成功"];
    }else{
        [self.view showTiShiMessage:@"分享失败"];
    }
}


#pragma mark - 收藏
- (void)shoucang:(UITapGestureRecognizer *)tapGes
{
    // 防止多次点击
    if (self.canShouCang == YES) {
        self.canShouCang = NO;
        NSLog(@"收藏或取消");
        NSString *isCollect = [NSString stringWithFormat:@"%@", [self.ziXunContentDic valueForKey:@"is_collected"]];
        NSString *newsID = [NSString stringWithFormat:@"%@", [self.ziXunContentDic valueForKey:@"id"]];
        NSString *urlString = [NSString stringWithFormat:@"http://120.26.129.84/api/news/collect?token=%@", kCurrentUserToken];
        NSDictionary *paramaterDic = @{@"news_id": newsID};
        if ([isCollect isEqualToString:@"0"]) {
            // 说明未收藏,想要收藏
            AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
            [manager POST:urlString parameters:paramaterDic success:^(NSURLSessionDataTask *task, id responseObject) {
                NSDictionary *statusDic = [responseObject valueForKey:@"status"];
                NSString *msgString = [statusDic valueForKey:@"msg"];
                if ([msgString isEqualToString:@"收藏成功"]) {
                    self.shoucangImageV.image = [UIImage imageNamed:@"suocangguo-chanpin"];
                    [self.ziXunContentDic setValue:@"1" forKey:@"is_collected"];
                }
                // 开启收藏
                self.canShouCang = YES;
            } failure:^(NSURLSessionDataTask *task, NSError *error) {
                NSLog(@"失败");
                // 开启收藏
                self.canShouCang = YES;
            }];
            
        } else if ([isCollect isEqualToString:@"1"]) {
            // 说明收藏过了,想要取消收藏
            AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
            [manager DELETE:urlString parameters:paramaterDic success:^(NSURLSessionDataTask *task, id responseObject) {
                NSDictionary *statusDic = [responseObject valueForKey:@"status"];
                NSString *msgString = [statusDic valueForKey:@"msg"];
                if ([msgString isEqualToString:@"取消收藏成功"]) {
                    self.shoucangImageV.image = [UIImage imageNamed:@"weishoucang-chanpin"];
                    [self.ziXunContentDic setValue:@"0" forKey:@"is_collected"];
                    
                }
                // 开启收藏
                self.canShouCang = YES;
            } failure:^(NSURLSessionDataTask *task, NSError *error) {
                // 开启收藏
                self.canShouCang = YES;
            }];
        }
    }
    
    
}

#pragma mark - 检查网络并建立数据源
- (void)searchNetAndAddData
{
    if ([[[NetStatusHandle shareHandle] getNetStatus] isEqualToString:@"YES"]) {
        // 说明有网络
        // 建立数据源
        [self addData];
        // 建立计时器，计算是否超时
        self.myTimer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(goTimeOnZiXun:) userInfo:nil repeats:YES];
        [[NSRunLoop currentRunLoop] addTimer:self.myTimer forMode:NSRunLoopCommonModes];
        self.numberOfTime = 0;
        
        // 开始动画
        [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] startAnimation];
    } else {
        NSLog(@"没有网络");
        // 添加提示框
        [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"通知" Content:kNoNetNoRefresh ToView:self];
    }
}

#pragma mark - 计时器方法
- (void)goTimeOnZiXun:(NSTimer *)timer
{
    self.numberOfTime++;
    NSLog(@"咨询页时间= %ld", self.numberOfTime);
    if (self.numberOfTime > 15) {
        NSLog(@"咨询页请求超时");
        self.numberOfTime = 0;
        [self.myTimer invalidate];
        // 关闭动画
        [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] stopAnimation];
        // 添加提示框
        [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"通知" Content:kQingQiuChaoShiNoReFresh ToView:self];
    }
}

#pragma mark - 添加数据
- (void)addData
{
    
    // 初始化
    self.ziXunContentDic = [NSMutableDictionary dictionary];
    self.pingLunOfZiXunArray = [NSMutableArray array];
    self.relateZiXunArray = [NSMutableArray array];
    NSLog(@"咨询ID = %@", self.ziXunID);
    NSString *url = [NSString stringWithFormat:@"http://120.26.129.84/api/news/info/%@?token=%@", self.ziXunID, kCurrentUserToken];
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager GET:url parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        if (!responseObject) {
            return;
        }
        
        
        
        NSDictionary *newDic = [responseObject valueForKey:@"news"];
        
        
        [self.ziXunContentDic setValue:[newDic valueForKey:@"id"]  forKey:@"id"];
        [self.ziXunContentDic setValue:[newDic valueForKey:@"comment_num"] forKey:@"comment_num"];
        [self.ziXunContentDic setValue:[newDic valueForKey:@"like_num"] forKey:@"like_num"];
        [self.ziXunContentDic setValue:[newDic valueForKey:@"is_like"] forKey:@"is_like"];
        [self.ziXunContentDic setValue:[newDic valueForKey:@"is_collected"] forKey:@"is_collected"];
        [self.ziXunContentDic setValue:[newDic valueForKey:@"content_url"] forKey:@"content_url"];
        NSArray *conmentsArray = [newDic valueForKey:@"comments"];
        // 构建navigation右上角的
        [self collectAndShare];
        // 所有评论
        for (NSDictionary *tempDic in conmentsArray) {
            ZiXunGeRenPingLunModel *model = [[ZiXunGeRenPingLunModel alloc] init];
            [model setValuesForKeysWithDictionary:tempDic];
            [self.pingLunOfZiXunArray addObject:model];
        }
        // 热门评论
        self.hotPingLunArray = [NSMutableArray array];
        NSArray *hotcommentsArray = [newDic valueForKey:@"hotcomments"];
        for (NSDictionary *tempDic in hotcommentsArray) {
            ZiXunGeRenPingLunModel *model = [[ZiXunGeRenPingLunModel alloc] init];
            [model setValuesForKeysWithDictionary:tempDic];
            [self.hotPingLunArray addObject:model];
        }
        
        // 相关咨询
        NSArray *relateNewsArray = [responseObject valueForKey:@"relateNews"];
        for (NSDictionary *tempDic in relateNewsArray) {
            ZiXunModel *model = [[ZiXunModel alloc] init];
            [model setValuesForKeysWithDictionary:tempDic];
            [self.relateZiXunArray addObject:model];
        }
        //        NSLog(@"self.ziXunContentDic =  %@", self.ziXunContentDic);
        //        NSLog(@"self.pingLunOfZiXunArray = %@", self.pingLunOfZiXunArray);
        
        //        NSLog(@"self.relateZiXunArray = %@", self.relateZiXunArray);
        [self addMySubview];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        NSLog(@"获取失败");
        // 关闭动画
        [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] stopAnimation];
        // 添加提示框
        [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"通知" Content:kHuoQuDataShiBaiNoRefresh ToView:self];
        // 暂停计时器
        [self.myTimer invalidate];
        self.numberOfTime = 0;
    }];
}

#pragma mark - 布局
- (void)addMySubview
{
    self.backGroundView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    self.backGroundView.backgroundColor = [UIColor whiteColor];
    self.backGroundView.contentSize = CGSizeMake(kScreenWidth, 3 * kScreenHeight);
    //  self.backGroundView.showsVerticalScrollIndicator = NO;
    self.backGroundView.bounces = NO;
    
    [self.view addSubview:_backGroundView];
    
    self.myWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 100 * kAdjustParamater)];
    self.myWebView.delegate = self;
    self.myWebView.backgroundColor = [UIColor whiteColor];
    
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[self.ziXunContentDic valueForKey:@"content_url"]]];
    [self.myWebView loadRequest:request];
    [self.backGroundView addSubview:_myWebView];
    
    
    
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    //    修改图片大小
    //        [webView stringByEvaluatingJavaScriptFromString:
    //         @"var script = document.createElement('script');"
    //         "script.type = 'text/javascript';"
    //         "script.text = \"function ResizeImages() { "
    //         "var myimg,oldwidth;"
    //         "var maxwidth = 320;" //缩放系数
    //         "for(i=0;i < document.images.length;i++){"
    //         "myimg = document.images[i];"
    //         "if(myimg.width > maxwidth){"
    //         "oldwidth = myimg.width;"
    //         "myimg.width = maxwidth;"
    //         "myimg.height = myimg.height * (maxwidth/oldwidth);"
    //         "}"
    //         "}"
    //         "}\";"
    //         "document.getElementsByTagName('head')[0].appendChild(script);"];
    //
    //        [webView stringByEvaluatingJavaScriptFromString:@"ResizeImages();"];
    
    [webView stringByEvaluatingJavaScriptFromString:
     @"var script = document.createElement('script');"
     "script.type = 'text/javascript';"
     "script.text = \"function ResizeImages() { "
     "var myimg,oldwidth, newheight;"
     "var maxwidth=300;" //缩放系数
     "for(i=0;i <document.images.length;i++){"
     "myimg = document.images;"
     "myimg.setAttribute('style','max-width:300px;height:auto')"
     "}"
     "}\";"
     "document.getElementsByTagName('head')[0].appendChild(script);"];
    
    
    [webView stringByEvaluatingJavaScriptFromString:@"ResizeImages();"];
    
    
    CGFloat height = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] floatValue];
    CGRect newFrame = webView.frame;
    newFrame.size.height = height;
    webView.frame = newFrame;
    // 将计时器置为0
    self.numberOfTime = 0;
    [self.myTimer invalidate];
    // 结束动画
    [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] stopAnimation];
    [self addMyTableView];
}

#pragma mark - 添加tableView
- (void)addMyTableView
{
    self.ziXunTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.myWebView.bottom, kScreenWidth, kScreenHeight + 80 * kAdjustParamater) style:UITableViewStylePlain];
    self.ziXunTableView.dataSource = self;
    self.ziXunTableView.delegate = self;
    // self.ziXunTableView.bounces  = NO;
    self.ziXunTableView.scrollEnabled = NO;
    self.ziXunTableView.backgroundColor = [UIColor whiteColor];
    [self.backGroundView addSubview:_ziXunTableView];
    
#warning  构建表头
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 77 * kAdjustParamater)];
    //  headerView.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.1];
    headerView.userInteractionEnabled = YES;
    self.ziXunTableView.tableHeaderView = headerView;
    
    // 更多产品
    UIButton *moreProductButton = [UIButton buttonWithType:UIButtonTypeSystem];
    moreProductButton.frame = CGRectMake(95 / 2 * kAdjustParamater, 23 * kAdjustParamater, 115 * kAdjustParamater, 30 * kAdjustParamater);
    moreProductButton.backgroundColor = kCyanColor;
    [moreProductButton setTitle:@"更多产品" forState:UIControlStateNormal];
    [moreProductButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    moreProductButton.layer.cornerRadius = 5 * kAdjustParamater;
    moreProductButton.titleLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:k18Big];
    [moreProductButton addTarget:self action:@selector(moreProduct:) forControlEvents:UIControlEventTouchUpInside];
    [headerView addSubview:moreProductButton];
    
    // 热门帖子
    UIButton *hotTieZiButton = [UIButton buttonWithType:UIButtonTypeSystem];
    hotTieZiButton.frame = CGRectMake(moreProductButton.right + 50 * kAdjustParamater, moreProductButton.top, 115 * kAdjustParamater, 30 * kAdjustParamater);
    hotTieZiButton.backgroundColor = kCyanColor;
    [hotTieZiButton setTitle:@"热门帖子" forState:UIControlStateNormal];
    [hotTieZiButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [hotTieZiButton addTarget:self action:@selector(hotTieZi:) forControlEvents:UIControlEventTouchUpInside];
    hotTieZiButton.layer.cornerRadius = 5 * kAdjustParamater;
    hotTieZiButton.titleLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:k18Big];
    [headerView addSubview:hotTieZiButton];
    
#warning  构建表尾
    self.footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 86 * kAdjustParamater)];
    self.footerView.userInteractionEnabled = YES;
    //  footerView.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.1];
    self.ziXunTableView.tableFooterView = self.footerView;
    // 灰色条
    UILabel *grayLineOnFooter = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 2 * kAdjustParamater)];
    grayLineOnFooter.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
    [self.footerView addSubview:grayLineOnFooter];
    
    // 发表评论背景view
    UIView *pingLunView = [[UIView alloc] initWithFrame:CGRectMake(37 * kAdjustParamater, 28 * kAdjustParamater, 115 * kAdjustParamater, 31 * kAdjustParamater)];
    pingLunView.backgroundColor = [UIColor whiteColor];
    pingLunView.userInteractionEnabled = YES;
    pingLunView.layer.cornerRadius = 7 * kAdjustParamater;
    pingLunView.layer.borderColor = [kCyanColor CGColor];
    pingLunView.layer.borderWidth = 1 * kAdjustParamater;
    [self.footerView addSubview:pingLunView];
    UITapGestureRecognizer *pingLunTapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pingLunGes:)];
    [pingLunView addGestureRecognizer:pingLunTapGes];
    
    // 发表评论的图片
    UIImageView *faBiaoPingLunImageV = [[UIImageView alloc] initWithFrame:CGRectMake(4 * kAdjustParamater, 5 * kAdjustParamater, 21 * kAdjustParamater, 21 * kAdjustParamater)];
    faBiaoPingLunImageV.image = [UIImage imageNamed:@"xiepinglunonzixun"];
    [pingLunView addSubview:faBiaoPingLunImageV];
    
    // 发表评论标题
    UILabel *faBiaoPingLunLabel = [[UILabel alloc] initWithFrame:CGRectMake(faBiaoPingLunImageV.right + 4 * kAdjustParamater, 5 * kAdjustParamater, 75 * kAdjustParamater, 21 * kAdjustParamater)];
    // faBiaoPingLunLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
    faBiaoPingLunLabel.text = @"发表评论";
    faBiaoPingLunLabel.textColor = kCyanColor;
    faBiaoPingLunLabel.textAlignment = NSTextAlignmentCenter;
    faBiaoPingLunLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:k18Big];
    [pingLunView addSubview:faBiaoPingLunLabel];
    
    // 点赞人数背景
    UIView *dianZanRenShuView = [[UIView alloc] initWithFrame:CGRectMake((375 - 152) * kAdjustParamater, 28 * kAdjustParamater, 115 * kAdjustParamater, 31 * kAdjustParamater)];
    dianZanRenShuView.backgroundColor = [UIColor whiteColor];
    dianZanRenShuView.userInteractionEnabled = YES;
    dianZanRenShuView.layer.cornerRadius = 7 * kAdjustParamater;
    dianZanRenShuView.layer.borderColor = [kYellowColor CGColor];
    dianZanRenShuView.layer.borderWidth = 1 * kAdjustParamater;
    [self.footerView addSubview:dianZanRenShuView];
    UITapGestureRecognizer *dianZanRenShuTapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dianZanRenGes:)];
    [dianZanRenShuView addGestureRecognizer:dianZanRenShuTapGes];
    // 点赞人数图片
    self.dianZanRenShuImageV = [[UIImageView alloc] initWithFrame:CGRectMake(4 * kAdjustParamater, 5 * kAdjustParamater, 21 * kAdjustParamater, 21 * kAdjustParamater)];
    NSString *isLike = [NSString stringWithFormat:@"%@", [self.ziXunContentDic valueForKey:@"is_like"]];
    if ([isLike isEqualToString:@"0"]) {
        // 说明不喜欢
        self.dianZanRenShuImageV.image = [UIImage imageNamed:@"weidianzan-zixun"];
    } else if ([isLike isEqualToString:@"1"]) {
        self.dianZanRenShuImageV.image = [UIImage imageNamed:@"dianzanguole-zixun"];
    }
    
    [dianZanRenShuView addSubview:_dianZanRenShuImageV];
    
    // 点赞人数标题
    self.dianZanRenShuLabel = [[UILabel alloc] initWithFrame:CGRectMake(faBiaoPingLunImageV.right + 4 * kAdjustParamater, 5 * kAdjustParamater, 75 * kAdjustParamater, 21 * kAdjustParamater)];
    // dianZanRenShuLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
    self.dianZanRenShuLabel.text = [NSString stringWithFormat:@"%@人点赞", [self.ziXunContentDic valueForKey:@"like_num"]];
    
    self.dianZanRenShuLabel.textColor = kCyanColor;
    self.dianZanRenShuLabel.textAlignment = NSTextAlignmentCenter;
    self.dianZanRenShuLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:k18Big];
    [dianZanRenShuView addSubview:_dianZanRenShuLabel];
    NSLog(@"改动前: %f", self.dianZanRenShuLabel.width);
    
    // 自适应宽度
    CGRect newFrameOfDianZanRenShu = self.dianZanRenShuLabel.frame;
    newFrameOfDianZanRenShu.size.width = [[NetStatusHandle shareHandle] adjustWidth:self.dianZanRenShuLabel.text size:18 height:21];
    if (newFrameOfDianZanRenShu.size.width < 75 * kAdjustParamater) {
        
    } else {
        self.dianZanRenShuLabel.frame = newFrameOfDianZanRenShu;
        NSLog(@"改动后: %f", self.dianZanRenShuLabel.width);
        dianZanRenShuView.width = self.dianZanRenShuLabel.width + 29 * kAdjustParamater + 9 * kAdjustParamater;
    }
    
    
    //self.ziXunTableView.contentSize = CGSizeMake(kScreenWidth, footerView.bottom + 50 * kAdjustParamater);
    self.ziXunTableView.frame = CGRectMake(0, self.myWebView.bottom, kScreenWidth, self.footerView.bottom);
    NSLog(@"表尾bottom = %f", self.footerView.bottom);
    NSLog(@"tableview bottom = %f", self.ziXunTableView.bottom);
    
    // 进行scrollview的调整
    self.backGroundView.contentSize = CGSizeMake(kScreenWidth, self.myWebView.height + self.ziXunTableView.height + 100 * kAdjustParamater);
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return self.hotPingLunArray.count;
    }
    if (section == 1) {
        // 评论
        if (self.pingLunOfZiXunArray.count < 2) {
            return self.pingLunOfZiXunArray.count;
        } else {
            return 2;
        }
    } else if (section == 2) {
        return self.relateZiXunArray.count;
    }
    
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        static NSString *identifier = @"pingLunOnZiXunCelll";
        PingLunOnZiXunTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell == nil) {
            cell = [[PingLunOnZiXunTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (self.hotPingLunArray.count > indexPath.row) {
            ZiXunGeRenPingLunModel *model = self.hotPingLunArray[indexPath.row];
            cell.model = model;
        }
        UITapGestureRecognizer *dianZanTapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dianZanGes:)];
        [cell.dianZanImageV addGestureRecognizer:dianZanTapGes];
        
        UITapGestureRecognizer *laJiTongTapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(laJiTongGes:)];
        [cell.laJiTongImageV addGestureRecognizer:laJiTongTapGes];
        return cell;
    }
    if (indexPath.section == 1) {
        static NSString *identifier = @"pingLunOnZiXunCelll";
        PingLunOnZiXunTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell == nil) {
            cell = [[PingLunOnZiXunTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (self.pingLunOfZiXunArray.count > indexPath.row) {
            ZiXunGeRenPingLunModel *model = self.pingLunOfZiXunArray[indexPath.row];
            cell.model = model;
        }
        UITapGestureRecognizer *dianZanTapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dianZanGes:)];
        [cell.dianZanImageV addGestureRecognizer:dianZanTapGes];
        
        UITapGestureRecognizer *laJiTongTapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(laJiTongGes:)];
        [cell.laJiTongImageV addGestureRecognizer:laJiTongTapGes];
        return cell;
    } else if (indexPath.section == 2) {
        static NSString *identifer = @"ziXunCell";
        ZiXunTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifer];
        if (cell == nil) {
            cell = [[ZiXunTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if (self.relateZiXunArray.count > indexPath.row) {
            ZiXunModel *model = self.relateZiXunArray[indexPath.row];
            cell.model = model;
        }
        return cell;
    }
    return nil;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 37 * kAdjustParamater)];
        headView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.05];
        UILabel *reMenPingLunLabel = [[UILabel alloc] initWithFrame:CGRectMake(15 * kAdjustParamater, 8 * kAdjustParamater, 150 * kAdjustParamater, 20 * kAdjustParamater)];
        reMenPingLunLabel.text = @"热门评论";
        reMenPingLunLabel.textColor = [UIColor blackColor];
        reMenPingLunLabel.textAlignment = NSTextAlignmentLeft;
        reMenPingLunLabel.font = [UIFont fontWithName:@"ArialMT" size:k17Big];
        [headView addSubview:reMenPingLunLabel];
        return headView;
    } else if (section == 1) {
        UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 37 * kAdjustParamater)];
        headView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.05];
        // 评论
        UILabel *pingLun = [[UILabel alloc] initWithFrame:CGRectMake(15 * kAdjustParamater, 8 * kAdjustParamater, 150 * kAdjustParamater, 20 * kAdjustParamater)];
        //   pingLun.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
        pingLun.text = [NSString stringWithFormat:@"评论    %ld", self.pingLunOfZiXunArray.count];
        pingLun.textColor = [UIColor blackColor];
        pingLun.textAlignment = NSTextAlignmentLeft;
        pingLun.font = [UIFont fontWithName:@"ArialMT" size:k17Big];
        [headView addSubview:pingLun];
        
        // 点赞数
        UILabel *dianZanLabel = [[UILabel alloc] initWithFrame:CGRectMake((375 - 115) * kAdjustParamater, pingLun.top, 100 * kAdjustParamater, 20 * kAdjustParamater)];
        //  dianZanLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
        // 统计评论赞的数量
        NSInteger zanCount = 0;
        for (int i = 0; i < self.pingLunOfZiXunArray.count; i++) {
            ZiXunGeRenPingLunModel *model = self.pingLunOfZiXunArray[i];
            NSInteger tempCount = [model.like_num integerValue];
            zanCount = zanCount + tempCount;
        }
        dianZanLabel.text = [NSString stringWithFormat:@"赞   %ld", zanCount];
        dianZanLabel.textColor = [UIColor blackColor];
        dianZanLabel.textAlignment = NSTextAlignmentRight;
        dianZanLabel.font = [UIFont fontWithName:@"ArialMT" size:k17Big];
        [headView addSubview:dianZanLabel];
        return headView;
    } else if (section == 2) {
        UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 37 * kAdjustParamater)];
        headView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.05];
        // 评论
        UILabel *caiXiangDuLabel = [[UILabel alloc] initWithFrame:CGRectMake(15 * kAdjustParamater, 8 * kAdjustParamater, 150 * kAdjustParamater, 20 * kAdjustParamater)];
        //    caiXiangDuLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
        caiXiangDuLabel.text = @"猜你还想读";
        caiXiangDuLabel.textColor = [UIColor blackColor];
        caiXiangDuLabel.textAlignment = NSTextAlignmentLeft;
        caiXiangDuLabel.font = [UIFont fontWithName:@"ArialMT" size:k17Big];
        [headView addSubview:caiXiangDuLabel];
        return headView;
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.section == 1|| indexPath.section == 0) {
        // 动态返回高度
        PingLunOnZiXunTableViewCell *pingLunCell = (PingLunOnZiXunTableViewCell *)[self tableView:self.ziXunTableView cellForRowAtIndexPath:indexPath];
        return pingLunCell.grayBackGroundView.bottom + 12 * kAdjustParamater;
    } else if (indexPath.section == 2) {
        return 85 * kAdjustParamater;
    }
    return 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    
    return 37 * kAdjustParamater;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    if (section == 0) {
        return nil;
    } else if (section == 1) {
        UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 65 * kAdjustParamater)];
        footerView.userInteractionEnabled = YES;
        //  footerView.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.1];
        // 灰色条
        UILabel *grayLineOnFoot = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 1 * kAdjustParamater)];
        grayLineOnFoot.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
        [footerView addSubview:grayLineOnFoot];
        // 查看更多评论
        UIButton *seeMorePingLunButton = [UIButton buttonWithType:UIButtonTypeSystem];
        seeMorePingLunButton.frame = CGRectMake((375 - 154) / 2 * kAdjustParamater, 15 * kAdjustParamater, 154 * kAdjustParamater, 36 * kAdjustParamater);
        seeMorePingLunButton.backgroundColor = [UIColor whiteColor];
        seeMorePingLunButton.titleLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:k16Big];
        [seeMorePingLunButton setTitle:@"查看更多评论" forState:UIControlStateNormal];
        [seeMorePingLunButton setTitleColor:kYellowColor forState:UIControlStateNormal];
        [seeMorePingLunButton addTarget:self action:@selector(seeMorePingLun:) forControlEvents:UIControlEventTouchUpInside];
        seeMorePingLunButton.layer.borderWidth = 1 * kAdjustParamater;
        seeMorePingLunButton.layer.borderColor = [kYellowColor CGColor];
        seeMorePingLunButton.layer.cornerRadius = 7 * kAdjustParamater;
        [footerView addSubview:seeMorePingLunButton];
        return footerView;
    } else if (section == 2) {
        
        return nil;
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section == 0) {
        return 0;
    } else if (section == 1) {
        return 65 * kAdjustParamater;
    } else if (section == 2) {
        return 0;
    }
    return 0;
}

#pragma mark - 更多产品
- (void)moreProduct:(UIButton *)button
{
    NSLog(@"更多产品");
    ProductViewController *productVC = [[ProductViewController alloc] init];
    productVC.isJump = YES;
    [self.navigationController pushViewController:productVC animated:YES];
}

#pragma mark - 热门帖子
- (void)hotTieZi:(UIButton *)button
{
    NSLog(@"热门帖子");
    HotAndGreatViewController *vc=[[HotAndGreatViewController alloc]init];
    vc.myTitle=@"热门帖子";
    vc.selectedIndex=2;
    vc.translucentState=YES;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - 查看更多评论
- (void)seeMorePingLun:(UIButton *)button
{
    NSLog(@"查看更多评论");
    PingListViewController *pingListVC = [[PingListViewController alloc] init];
    __block ZiXunViewController *mySelf = self;
    // 进行model的更换
    pingListVC.rowOfModel = ^void(ZiXunGeRenPingLunModel *model, NSInteger row) {
        // 进行model的更换
        if (mySelf.pingLunOfZiXunArray.count > row) {
            [mySelf.pingLunOfZiXunArray replaceObjectAtIndex:row withObject:model];
            // 对相应的人们数据进行修改
            for (int i = 0; i < self.hotPingLunArray.count; i++) {
                ZiXunGeRenPingLunModel *hotModel = self.hotPingLunArray[i];
                if ([hotModel.content isEqualToString:model.content] && [hotModel.created_at isEqualToString:model.created_at]) {
                    [self.hotPingLunArray replaceObjectAtIndex:i withObject:model];
                }
            }
            [mySelf.ziXunTableView reloadData];
        }
    };
    
    // 删除对应行
    pingListVC.deleteRow = ^void(NSInteger row) {
        if (mySelf.pingLunOfZiXunArray.count > row) {
            ZiXunGeRenPingLunModel *ziXunModel = self.pingLunOfZiXunArray[row];
            // 对相应的人们数据进行修改
            for (int i = 0; i < self.hotPingLunArray.count; i++) {
                ZiXunGeRenPingLunModel *hotModel = self.hotPingLunArray[i];
                if ([hotModel.content isEqualToString:ziXunModel.content] && [hotModel.created_at isEqualToString:ziXunModel.created_at]) {
                    [self.hotPingLunArray removeObjectAtIndex:i];
                }
            }
            [mySelf.pingLunOfZiXunArray removeObjectAtIndex:row];
            [mySelf.ziXunTableView reloadData];
            // 重新对长度进行定义
            mySelf.ziXunTableView.frame = CGRectMake(0, mySelf.myWebView.bottom, kScreenWidth, mySelf.footerView.bottom);
            // 进行scrollview的调整
            self.backGroundView.contentSize = CGSizeMake(kScreenWidth, self.myWebView.height + self.ziXunTableView.height + 100 * kAdjustParamater);
        }
    };
    pingListVC.pingLunArray = self.pingLunOfZiXunArray;
    [self.navigationController pushViewController:pingListVC animated:YES];
}

#pragma mark - 发表评论
- (void)pingLunGes:(UITapGestureRecognizer *)tapGes
{
    NSLog(@"发表评论");
    SendPingLunViewController *sendPingLunVC = [[SendPingLunViewController alloc] init];
    __block ZiXunViewController *mySelf = self;
    sendPingLunVC.addZiXun = ^void(ZiXunGeRenPingLunModel *model) {
        // 重新获取数据
        [mySelf addData];
    };
    sendPingLunVC.ziXunID = [NSString stringWithFormat:@"%@", [self.ziXunContentDic valueForKey:@"id"]];
    sendPingLunVC.isZiXunOrGuanFangActivity = @"ziXun";
    [self.navigationController pushViewController:sendPingLunVC animated:YES];
}

#pragma mark - 点赞人数
- (void)dianZanRenGes:(UITapGestureRecognizer *)tapGes
{
    // 防止多次点击
    if (self.canZhengTiDianZan == YES) {
        NSLog(@"咨询点赞或者取消点赞");
        self.canZhengTiDianZan = NO;
        // 获取点赞人数
        __block NSInteger likeNum = [[self.ziXunContentDic valueForKey:@"like_num"] integerValue];
        
        NSString *isLike = [NSString stringWithFormat:@"%@", [self.ziXunContentDic valueForKey:@"is_like"]];
        if ([isLike isEqualToString:@"0"]) {
            // 说明不喜欢,此时想要喜欢
            NSString *newsID = [NSString stringWithFormat:@"%@", [self.ziXunContentDic valueForKey:@"id"]];
            //      NSDictionary *paramaterDic = @{@"token": kCurrentUserToken, @"news_id":newsID};
            NSString *urlString = [NSString stringWithFormat:@"http://120.26.129.84/api/news/like?token=%@", kCurrentUserToken];
            NSDictionary *paramaterDic = @{@"news_id":newsID};
            AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
            [manager POST:urlString parameters:paramaterDic success:^(NSURLSessionDataTask *task, id responseObject) {
                NSDictionary *statusDic = [responseObject valueForKey:@"status"];
                NSString *msg = [statusDic valueForKey:@"msg"];
                if ([msg isEqualToString:@"点赞成功"]) {
                    // 说明点赞成功
                    //    NSLog(@"点赞成功");
                    // 更改点赞变量
                    [self.ziXunContentDic setValue:@"1" forKey:@"is_like"];
                    // 将当前点赞的数量加1
                    likeNum++;
                    [self.ziXunContentDic setValue:[NSNumber numberWithInteger:likeNum] forKey:@"like_num"];
                    self.dianZanRenShuImageV.image = [UIImage imageNamed:@"dianzanguole-zixun"];
                    self.dianZanRenShuLabel.text = [NSString stringWithFormat:@"%@人点赞", [self.ziXunContentDic valueForKey:@"like_num"]];
                }
                // 开启点赞
                self.canZhengTiDianZan = YES;
            } failure:^(NSURLSessionDataTask *task, NSError *error) {
                // NSLog(@"token过期");
                NSLog(@"错误= %@", error);
                [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"提示" Content:@"点赞失败，请重试" ToView:self];
                // 开启点赞
                self.canZhengTiDianZan = YES;
            }];
        } else if ([isLike isEqualToString:@"1"]) {
            // 说明喜欢,此时想要不喜欢
            NSString *newsID = [NSString stringWithFormat:@"%@", [self.ziXunContentDic valueForKey:@"id"]];
            
            // NSDictionary *paramaterDic = @{@"token": kCurrentUserToken, @"news_id":newsID};
            NSString *urlString = [NSString stringWithFormat:@"http://120.26.129.84/api/news/like?token=%@", kCurrentUserToken];
            NSDictionary *paramaterDic = @{@"news_id":newsID};
            AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
            [ manager DELETE:urlString parameters:paramaterDic success:^(NSURLSessionDataTask *task, id responseObject) {
                NSDictionary *statusDic = [responseObject valueForKey:@"status"];
                NSString *msg = [statusDic valueForKey:@"msg"];
                if ([msg isEqualToString:@"取消点赞成功"]) {
                    // 说明取消点赞成功
                    //    NSLog(@"取消点赞成功");
                    // 更改点赞变量
                    [self.ziXunContentDic setValue:@"0" forKey:@"is_like"];
                    likeNum--;
                    [self.ziXunContentDic setValue:[NSNumber numberWithInteger:likeNum] forKey:@"like_num"];
                    self.dianZanRenShuImageV.image = [UIImage imageNamed:@"weidianzan-zixun"];
                    self.dianZanRenShuLabel.text = [NSString stringWithFormat:@"%@人点赞", [self.ziXunContentDic valueForKey:@"like_num"]];
                }
                self.canZhengTiDianZan = YES;
            } failure:^(NSURLSessionDataTask *task, NSError *error) {
                NSLog(@"token过期");
                // 开启点赞
                self.canZhengTiDianZan = YES;
                [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"提示" Content:@"点赞失败，请重试" ToView:self];
            }];
            
            
        }
        
    }
    
}

#pragma mark - 对发表的评论进行点击
- (void)dianZanGes:(UITapGestureRecognizer *)tapGes
{
    // 防止多次点击，现在是只有在等待上一次数据返回以后才能点击下一次，就是说不能同时对多个评论进行点赞，可以优化(以后我会优化的)
    if (self.pingLunShiFouKeYiDianZan == YES) {
        NSLog(@"对评论进行点赞或取消");
        self.pingLunShiFouKeYiDianZan = NO;
        UIView *contentV = [tapGes.view superview];
        PingLunOnZiXunTableViewCell *cell = (PingLunOnZiXunTableViewCell *)[contentV superview];
        NSIndexPath *tempIndexPath = [self.ziXunTableView indexPathForCell:cell];
        NSLog(@"对section = %ld, row = %ld进行点赞",tempIndexPath.section , tempIndexPath.row);
        if (tempIndexPath.section == 0) {
            if (self.hotPingLunArray.count > tempIndexPath.row) {
                ZiXunGeRenPingLunModel *model = self.hotPingLunArray[tempIndexPath.row];
                // 当前用户是否喜欢
                NSString *currentUserIsLike = [NSString stringWithFormat:@"%@", model.is_liked];
                NSString *newscomment_idString = [NSString stringWithFormat:@"%@", model.myUserID];
                __block NSInteger likeNum = [model.like_num integerValue];
                if ([currentUserIsLike isEqualToString:@"0"]) {
                    // 说明不喜欢，想要喜欢
                    NSString *urlString = [NSString stringWithFormat:@"http://120.26.129.84/api/news/commentlike?token=%@", kCurrentUserToken];
                    NSDictionary *paramaterDic = @{@"newscomment_id": newscomment_idString};
                    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
                    [manager POST:urlString parameters:paramaterDic success:^(NSURLSessionDataTask *task, id responseObject) {
                        if (!responseObject) {
                            return;
                        }
                        NSDictionary *statusDic = [responseObject valueForKey:@"status"];
                        if ([[statusDic valueForKey:@"msg"] isEqualToString:@"点赞成功"]) {
                            NSLog(@"热门评论点赞成功");
                            model.is_liked = @"1";
                            likeNum++;
                            model.like_num = [NSString stringWithFormat:@"%ld", likeNum];
                            
                            cell.dianZanImageV.image = [UIImage imageNamed:@"dianzanguole-zixun"];
                            // 取出对应评论的model
                            for (int i = 0; i < self.pingLunOfZiXunArray.count; i++) {
                                ZiXunGeRenPingLunModel *pingLunModel = self.pingLunOfZiXunArray[i];
                                if ([pingLunModel.content isEqualToString:model.content] && [pingLunModel.created_at isEqualToString:model.created_at]) {
                                    pingLunModel.like_num = [NSString stringWithFormat:@"%ld", likeNum];
                                    pingLunModel.is_liked = @"1";
                                }
                            }
                            [self.ziXunTableView reloadData];
                        }
                        // 开启评论点赞
                        self.pingLunShiFouKeYiDianZan = YES;
                    } failure:^(NSURLSessionDataTask *task, NSError *error) {
                        // 开启评论点赞
                        self.pingLunShiFouKeYiDianZan = YES;
                        [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"提示" Content:@"点赞失败，请重试" ToView:self];
                    }];
                } else if ([currentUserIsLike isEqualToString:@"1"]) {
                    // 说明喜欢，想要不喜欢
                    NSString *urlString = [NSString stringWithFormat:@"http://120.26.129.84/api/news/commentlike?token=%@", kCurrentUserToken];
                    NSDictionary *paramaterDic = @{@"newscomment_id": newscomment_idString};
                    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
                    [manager DELETE:urlString parameters:paramaterDic success:^(NSURLSessionDataTask *task, id responseObject) {
                        if (!responseObject) {
                            return;
                        }
                        NSDictionary *statusDic = [responseObject valueForKey:@"status"];
                        if ([[statusDic valueForKey:@"msg"] isEqualToString:@"取消成功"]) {
                            NSLog(@"热门评论点赞取消成功");
                            model.is_liked = @"0";
                            likeNum--;
                            model.like_num = [NSString stringWithFormat:@"%ld", likeNum];
                            
                            cell.dianZanImageV.image = [UIImage imageNamed:@"weidianzan-zixun"];
                            // 取出对应评论的model
                            for (int i = 0; i < self.pingLunOfZiXunArray.count; i++) {
                                ZiXunGeRenPingLunModel *pingLunModel = self.pingLunOfZiXunArray[i];
                                if ([pingLunModel.content isEqualToString:model.content] && [pingLunModel.created_at isEqualToString:model.created_at]) {
                                    pingLunModel.like_num = [NSString stringWithFormat:@"%ld", likeNum];
                                    pingLunModel.is_liked = @"0";
                                }
                            }
                            [self.ziXunTableView reloadData];
                        }
                        // 开启评论点赞
                        self.pingLunShiFouKeYiDianZan = YES;
                    } failure:^(NSURLSessionDataTask *task, NSError *error) {
                        // 开启评论点赞
                        self.pingLunShiFouKeYiDianZan = YES;
                        [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"提示" Content:@"点赞失败，请重试" ToView:self];
                    }];
                }
            }
        } else if (tempIndexPath.section == 1) {
            if (self.pingLunOfZiXunArray.count > tempIndexPath.row) {
                ZiXunGeRenPingLunModel *model = self.pingLunOfZiXunArray[tempIndexPath.row];
                // 当前用户是否喜欢
                NSString *currentUserIsLike = [NSString stringWithFormat:@"%@", model.is_liked];
                NSString *newscomment_idString = [NSString stringWithFormat:@"%@", model.myUserID];
                __block NSInteger likeNum = [model.like_num integerValue];
                if ([currentUserIsLike isEqualToString:@"0"]) {
                    // 说明不喜欢，想要喜欢
                    NSString *urlString = [NSString stringWithFormat:@"http://120.26.129.84/api/news/commentlike?token=%@", kCurrentUserToken];
                    NSDictionary *paramaterDic = @{@"newscomment_id": newscomment_idString};
                    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
                    [manager POST:urlString parameters:paramaterDic success:^(NSURLSessionDataTask *task, id responseObject) {
                        if (!responseObject) {
                            return;
                        }
                        NSDictionary *statusDic = [responseObject valueForKey:@"status"];
                        if ([[statusDic valueForKey:@"msg"] isEqualToString:@"点赞成功"]) {
                            NSLog(@"普通评论点赞成功");
                            model.is_liked = @"1";
                            likeNum++;
                            model.like_num = [NSString stringWithFormat:@"%ld", likeNum];
                            
                            cell.dianZanImageV.image = [UIImage imageNamed:@"dianzanguole-zixun"];
                            // 修改对应热门评论的model
                            for (int i = 0; i < self.hotPingLunArray.count; i++) {
                                ZiXunGeRenPingLunModel *reMenModel = self.hotPingLunArray[i];
                                if ([reMenModel.content isEqualToString:model.content] && [reMenModel.created_at isEqualToString:model.created_at]) {
                                    reMenModel.like_num = [NSString stringWithFormat:@"%ld", likeNum];
                                    reMenModel.is_liked = @"1";
                                }
                            }
                            [self.ziXunTableView reloadData];
                        }
                        // 开启评论点赞
                        self.pingLunShiFouKeYiDianZan = YES;
                    } failure:^(NSURLSessionDataTask *task, NSError *error) {
                        // 开启评论点赞
                        self.pingLunShiFouKeYiDianZan = YES;
                        [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"提示" Content:@"点赞失败，请重试" ToView:self];
                    }];
                } else if ([currentUserIsLike isEqualToString:@"1"]) {
                    // 说明喜欢，想要不喜欢
                    NSString *urlString = [NSString stringWithFormat:@"http://120.26.129.84/api/news/commentlike?token=%@", kCurrentUserToken];
                    NSDictionary *paramaterDic = @{@"newscomment_id": newscomment_idString};
                    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
                    [manager DELETE:urlString parameters:paramaterDic success:^(NSURLSessionDataTask *task, id responseObject) {
                        if (!responseObject) {
                            return;
                        }
                        NSDictionary *statusDic = [responseObject valueForKey:@"status"];
                        if ([[statusDic valueForKey:@"msg"] isEqualToString:@"取消成功"]) {
                            NSLog(@"普通评论取消成功");
                            model.is_liked = @"0";
                            likeNum--;
                            model.like_num = [NSString stringWithFormat:@"%ld", likeNum];
                            
                            cell.dianZanImageV.image = [UIImage imageNamed:@"weidianzan-zixun"];
                            // 修改对应热门评论的model
                            for (int i = 0; i < self.hotPingLunArray.count; i++) {
                                ZiXunGeRenPingLunModel *reMenModel = self.hotPingLunArray[i];
                                if ([reMenModel.content isEqualToString:model.content] && [reMenModel.created_at isEqualToString:model.created_at]) {
                                    reMenModel.like_num = [NSString stringWithFormat:@"%ld", likeNum];
                                    reMenModel.is_liked = @"0";
                                }
                            }
                            [self.ziXunTableView reloadData];
                        }
                        
                        // 开启评论点赞
                        self.pingLunShiFouKeYiDianZan = YES;
                    } failure:^(NSURLSessionDataTask *task, NSError *error) {
                        // 开启评论点赞
                        self.pingLunShiFouKeYiDianZan = YES;
                        [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"提示" Content:@"点赞失败，请重试" ToView:self];
                    }];
                }
            }
        }
        
    }
    
}

#pragma mark - 垃圾桶点击
- (void)laJiTongGes:(UITapGestureRecognizer *)tapGes
{
    UIView *contentV = [tapGes.view superview];
    PingLunOnZiXunTableViewCell *cell = (PingLunOnZiXunTableViewCell *)[contentV superview];
    NSIndexPath *tempIndexPath = [self.ziXunTableView indexPathForCell:cell];
    //  NSLog(@"点击的%ld行", tempIndexPath.row);
    
    [self addAlertNoSuit:@"您确定删除该评论么" Row:tempIndexPath.row Section:tempIndexPath.section];
}

#pragma mark - 提醒框
- (void)addAlertNoSuit:(NSString *)content Row:(NSInteger)row Section:(NSInteger)section
{
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"警告" message:content preferredStyle:UIAlertControllerStyleAlert];
    // 修改标题颜色
    NSMutableAttributedString *title = [[NSMutableAttributedString alloc] initWithString:@"警告"];
    [title addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 2)];
    [title addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17] range:NSMakeRange(0, 2)];
    [alertVC setValue:title forKey:@"attributedTitle"];
    
    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        //   NSLog(@"确定");
        // 防止多次点击
        if (self.canClickLaJiTong == YES) {
            self.canClickLaJiTong = NO;
            NSString *urlString = [NSString stringWithFormat:@"http://120.26.129.84/api/news/comment?token=%@", kCurrentUserToken];
            if (section == 0) {
                if (self.hotPingLunArray.count > row) {
                    ZiXunGeRenPingLunModel *model = self.hotPingLunArray[row];
                    
                    NSString *pingLunID = [NSString stringWithFormat:@"%@", model.myUserID];
                    NSDictionary *paramaterDic = @{@"newscomment_id":pingLunID};
                    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
                    [manager DELETE:urlString parameters:paramaterDic success:^(NSURLSessionDataTask *task, id responseObject) {
                        NSDictionary *statusDic = [responseObject valueForKey:@"status"];
                        NSString *msgString = [statusDic valueForKey:@"msg"];
                        if ([msgString isEqualToString:@"删除成功"]) {
                            NSLog(@"删除成功");
                            ZiXunGeRenPingLunModel *hotModel = self.hotPingLunArray[row];
                            // 删除对应的评论数据
                            //  [self.pingLunOfZiXunArray removeObject:self.hotPingLunArray[row]];
                            for (int i = 0; i < self.pingLunOfZiXunArray.count; i++) {
                                ZiXunGeRenPingLunModel *pingLunModel = self.pingLunOfZiXunArray[i];
                                if ([pingLunModel.content isEqualToString:hotModel.content] && [pingLunModel.created_at isEqualToString:hotModel.created_at]) {
                                    [self.pingLunOfZiXunArray removeObjectAtIndex:i];
                                }
                            }
                            // 删除对应的数据
                            [self.hotPingLunArray removeObjectAtIndex:row];
                            
                            [self.ziXunTableView reloadData];
                            // 重新对长度进行定义
                            self.ziXunTableView.frame = CGRectMake(0, self.myWebView.bottom, kScreenWidth, self.footerView.bottom);
                            NSLog(@"表尾bottom = %f", self.footerView.bottom);
                            NSLog(@"tableview bottom = %f", self.ziXunTableView.bottom);
                            
                            // 进行scrollview的调整
                            self.backGroundView.contentSize = CGSizeMake(kScreenWidth, self.myWebView.height + self.ziXunTableView.height + 100 * kAdjustParamater);
                        }
                        // 开启点击
                        self.canClickLaJiTong = YES;
                    } failure:^(NSURLSessionDataTask *task, NSError *error) {
                        NSLog(@"错误error = %@", error);
                        // 开启点击
                        self.canClickLaJiTong = YES;
                        [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"提示" Content:@"删除失败，请重试" ToView:self];
                    }];
                }
                
            } else if (section == 1) {
                if (self.pingLunOfZiXunArray.count > row) {
                    ZiXunGeRenPingLunModel *model = self.pingLunOfZiXunArray[row];
                    
                    NSString *pingLunID = [NSString stringWithFormat:@"%@", model.myUserID];
                    NSDictionary *paramaterDic = @{@"newscomment_id":pingLunID};
                    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
                    [manager DELETE:urlString parameters:paramaterDic success:^(NSURLSessionDataTask *task, id responseObject) {
                        NSDictionary *statusDic = [responseObject valueForKey:@"status"];
                        NSString *msgString = [statusDic valueForKey:@"msg"];
                        if ([msgString isEqualToString:@"删除成功"]) {
                            NSLog(@"删除成功");
                            // 删除对应热门数据
                            ZiXunGeRenPingLunModel *pingLunModel = self.pingLunOfZiXunArray[row];
                            for (int i = 0; i < self.hotPingLunArray.count; i++) {
                                ZiXunGeRenPingLunModel *hotModel = self.hotPingLunArray[i];
                                if ([hotModel.content isEqualToString:pingLunModel.content] && [hotModel.created_at isEqualToString:pingLunModel.created_at]) {
                                    [self.hotPingLunArray removeObjectAtIndex:i];
                                }
                            }
                            // 删除对应的数据
                            [self.pingLunOfZiXunArray removeObjectAtIndex:row];
                            [self.ziXunTableView reloadData];
                            
                            // 重新对长度进行定义
                            self.ziXunTableView.frame = CGRectMake(0, self.myWebView.bottom, kScreenWidth, self.footerView.bottom);
                            NSLog(@"表尾bottom = %f", self.footerView.bottom);
                            NSLog(@"tableview bottom = %f", self.ziXunTableView.bottom);
                            
                            // 进行scrollview的调整
                            self.backGroundView.contentSize = CGSizeMake(kScreenWidth, self.myWebView.height + self.ziXunTableView.height + 100 * kAdjustParamater);
                        }
                        // 开启点击
                        self.canClickLaJiTong = YES;
                    } failure:^(NSURLSessionDataTask *task, NSError *error) {
                        NSLog(@"错误error = %@", error);
                        // 开启点击
                        self.canClickLaJiTong = YES;
                        [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"提示" Content:@"删除失败，请重试" ToView:self];
                    }];
                }
                
            }
            
        }
        
    }];
    [alertVC addAction:sureAction];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alertVC addAction:cancelAction];
    [self presentViewController:alertVC animated:YES completion:nil];
}

// 点击cell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 2) {
        ZiXunViewController *ziXunVC = [[ZiXunViewController alloc] init];
        if (self.relateZiXunArray.count > indexPath.row) {
            ZiXunModel *model = self.relateZiXunArray[indexPath.row];
            ziXunVC.ziXunID = [NSString stringWithFormat:@"%@", model.myZiXunId];
        }
        [self.navigationController pushViewController:ziXunVC animated:YES];
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
